package cn.iocoder.yudao.module.bpm.dal.dataobject.definition;

import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.zhxu.bs.bean.DbIgnore;
import cn.zhxu.bs.bean.SearchBean;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * BPM 工作流的表单定义
 * 用于工作流的申请表单，需要动态配置的场景
 *
 * @author 芋道源码
 */
@TableName(value = "bpm_form", autoResultMap = true)
@SearchBean(tables = "bpm_form")
public class BpmFormSearchBeanDO extends BaseDO {

    /**
     * 编号
     */
    @TableId
    private Long id;
    /**
     * 表单名
     */
    private String name;
    /**
     * 状态
     */
    private Integer status;
    /**
     * 表单的配置
     */
    private String conf;
    /**
     * 表单项的数组
     *
     * 目前直接将 https://github.com/JakHuang/form-generator 生成的 JSON 串，直接保存
     * 定义：https://github.com/JakHuang/form-generator/issues/46
     */
    @TableField(typeHandler = JacksonTypeHandler.class)
    private String fields;
    /**
     * 备注
     */
    private String remark;

    private String formKey;

    private String ckUrl;
    private String bjUrl;
    private String xzUrl;
    private String tableName;

    @DbIgnore
    private JSONArray fieldList;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getConf() {
        return conf;
    }

    public void setConf(String conf) {
        this.conf = conf;
    }

    public String getFields() {
        return fields;
    }

    public void setFields(String fields) {
        this.fields = fields;
        if (StringUtils.isNotEmpty(fields)) {
            try {
                JSONArray jsonArray = JSON.parseArray(fields);
                setFieldList(jsonArray);
            } catch (Exception e) {

            }
        }
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getFormKey() {
        return formKey;
    }

    public void setFormKey(String formKey) {
        this.formKey = formKey;
    }

    public JSONArray getFieldList() {
        return fieldList;
    }

    public void setFieldList(JSONArray fieldList) {
        this.fieldList = fieldList;
    }

    public String getCkUrl() {
        return ckUrl;
    }

    public void setCkUrl(String ckUrl) {
        this.ckUrl = ckUrl;
    }

    public String getBjUrl() {
        return bjUrl;
    }

    public void setBjUrl(String bjUrl) {
        this.bjUrl = bjUrl;
    }

    public String getXzUrl() {
        return xzUrl;
    }

    public void setXzUrl(String xzUrl) {
        this.xzUrl = xzUrl;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }
}
